﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TTSBLL;
using TTSModel;
using System.IO;
using System.Text;
using System.Drawing;
public partial class search_AirtightnessTek : System.Web.UI.Page
{
    private AirtightnessTek AirtightnessTekBLL;
    private DateTime startTime
    {
        get { return DateTime.Parse(ViewState["startTime"].ToString()); }
        set { ViewState["startTime"] = value; }
    }
    private DateTime endTime
    {
        get { return DateTime.Parse(ViewState["endTime"].ToString()); }
        set { ViewState["endTime"] = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //DateBindToGridView();
            this.GridView1.PagerSettings.Visible = false;//隐藏自带的分页
        }
      
    }

    public search_AirtightnessTek()
    {
        AirtightnessTekBLL = new AirtightnessTek();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DateBindToGridView();
    }
    /// <summary>
    /// 在 GridView 控件中的某个行被绑定到一个数据记录时发生。此事件通常用于在某个行被绑定到数据时修改该行的内容。
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    
    private void DateBindToGridView()
    {
        this.GridView1.Visible = true;
        if(this.RadioButton1.Checked)
        {
            startTime = DateTime.Parse(this.Text1.Value.Trim());
            endTime = DateTime.Parse(this.TextBox2.Value.Trim());
            this.GridView1.DataSource = AirtightnessTekBLL.AirtightnessTekInfo_GetbyDT(startTime, endTime);
        }
        if(this.RadioButton2.Checked)
        {          
            this.GridView1.DataSource = AirtightnessTekBLL.AirtightnessTekInfo_GetbyKccSN(this.TextBox1.Text.Trim());
        }
        this.GridView1.DataBind();
        this.ddlCurrentPage.Items.Clear();
        for (int i = 1; i <= this.GridView1.PageCount; i++)
        {
            this.ddlCurrentPage.Items.Add(i.ToString());
        }
        this.ddlCurrentPage.SelectedIndex = this.GridView1.PageIndex;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/search/searchMainHtml.aspx");
    }



    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        this.lblCurrentPage.Text = string.Format("当前第{0}页/总共{1}页", this.GridView1.PageIndex + 1, this.GridView1.PageCount);

        //遍历所有行设置边框样式
        foreach (TableCell tc in e.Row.Cells)
        {
            tc.Attributes["style"] = "border-color:Black";
        }
        //GridViewRow row = e.Row;
      
        //for (int i = -1; i < GridView1.Rows.Count; i++)
        //{
        //    //判断是否为数据行（排除头部和底部）
        //      if (row.RowType == DataControlRowType.DataRow)
        //      {
        //          int lbl = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "TestValue"));
        //          // int lbl = Convert.ToInt32(GridView1.Rows[i].Cells[4].ToString());
        //          if (lbl < 55)
        //          {
        //              e.Row.Cells[4].ForeColor = Color.Red;
        //          }
        //      }
           
        //}
        //用索引来取得编号
      /*  if (e.Row.RowIndex != -1)
        {
            int id = GridView1.PageIndex * GridView1.PageSize + e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = id.ToString();
        }*/
    }
    /// <summary>
    /// 重新绑定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.GridView1.PageIndex = this.ddlCurrentPage.SelectedIndex;
        DateBindToGridView();
    }
    protected void lnkbtnFrist_Click(object sender, EventArgs e)
    {
        this.GridView1.PageIndex = 0;
        DateBindToGridView();
    }
    protected void lnkbtnPre_Click(object sender, EventArgs e)
    {
        if (this.GridView1.PageIndex > 0)
        {
            this.GridView1.PageIndex = this.GridView1.PageIndex - 1;
            DateBindToGridView();
        }
    }
    protected void lnkbtnNext_Click(object sender, EventArgs e)
    {
        if (this.GridView1.PageIndex < this.GridView1.PageCount)
        {
            this.GridView1.PageIndex = this.GridView1.PageIndex + 1;
            DateBindToGridView();
        }
    }
    protected void lnkbtnLast_Click(object sender, EventArgs e)
    {
        this.GridView1.PageIndex = this.GridView1.PageCount;
        DateBindToGridView();
    }


    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        this.TextBox1.Text = ""; 
    }
    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        this.Text1.Value = "";
        this.TextBox2.Value = "";
    }
}